/*
 * @Author       : 吴豪
 * @Date         : 2021-12-4 15:56:22
 * @FilePath     : \book-manage-front\src\services\user.ts
 * @Description  : 用户管理页面接口文件
 */

import type { UserListType, UserList, userInfoType, addUserType } from '@/dataType';
import { request } from 'umi';



/**
 * 1.获取用户信息列表
 * @returns
 */
export async function getUserList(params: UserListType) {
  return request<{ rowsNum: number; list: UserList[] }>('/userManage/getUserList', { params });
}

/**
 * 2.获取状态列表
 * @returns 
 */
export async function getUserStateList() {
  return request<{ id: number; name: string }[]>('/userManage/getUserStateList', {});
}

/**
 * 3.更改用户状态 启用/禁用
 * @param aid
 * @returns
 */
export async function enableUser(aid: number) {
  return request('/userManage/enableUser', {
    data: {
      aid
    },
    method: 'POST',
  })
}

/**
 * 4.获取用户信息
 * @param userAid 
 * @returns 
 */
export async function getUserInfo(params: { aid: number }) {
  console.log(888, params)
  return request<{ name: string; phone: string; password: string; enclosureId?: string; enclosureName?: string }>('/userManage/getUserInfo',
    {
      params: params,
      method: 'GET'
    })
}

/**
 * 5.检查手机号是否存在
 * @param params 
 * @returns 
 */
export async function checkPhoneExist(params: { aid: number; phone: string }) {
  return request<{ isExist: boolean, userInfo?: userInfoType }>('/userManage/checkPhoneExist', {
    params,
    method: 'GET'
  })
}

/**
 * 7.删除附件
 * @param params 
 * @returns 
 */
export async function deleterEnclosure(params: { enclosureId: string; aid: number }) {
  return request('/userManage/deleterEnclosure', {
    data: params,
    method: 'POST'
  })

}

/**
 * 8.添加用户
 * @returns 
 */
export async function saveUserInfo(params: addUserType) {
  return request('/userManage/saveUserInfo', {
    data: params,
    method: 'POST'
  })
}

/**
 * 9.删除用户
 * @param params 
 * @returns 
 */
export async function deleteUser(params: { aid: number }) {
  return request('/userManage/deleteUser', {
    data: params,
    method: 'POST'
  })
}

/**
 * 10.下载附件
 * @param params 
 * @returns 
 */
export async function downloadEnclosure(params: { enclosureId: string }) {
  return request("/userManage/downloadEnclosure", { params, responseType: 'blob' })
}
